package com.eyas.im.server.nio;

import com.eyas.im.protocol.decoder.Decoder;
import com.eyas.im.protocol.decoder.StringDecoder;
import com.eyas.im.protocol.encoder.Encoder;
import com.eyas.im.protocol.encoder.StringEncoder;
import com.eyas.im.server.ServerConfiguration;

public class NioServerConfiguration extends ServerConfiguration {
    private long selectBlockTime = 1000L;
    private int bufferCapacity = 64*1024; //bytebuffer的大小

    private long ioReactorBlockTime = 5000L; //IOReactor线程从queue中读取待操作任务的阻塞时间

    private Class<? extends Encoder<?>> encoderClass = StringEncoder.class; //协议处理器，默认将字符串处理成UTF-8的byte数组
    private Class<? extends Decoder<?>> decoderClass = StringDecoder.class; //协议解析器，默认将byte数组转换为字符串，编码格式使用UTF-8

    /*用于检测并处理java nio在linux下的空轮询bug*/
    private boolean nioBugChecker = true; //是否启动NIO检测，默认启动
    private long nioBugIntervalThreshold = 100L;//两次selector之间，间隔时间小于该值时，被判定可能触发了bug
    private int nioBugPossibleCount = 50;//当被判定可能触发了bug的连续次数超过该值时，就判定确实发生了bug

    public NioServerConfiguration() {

    }

    public NioServerConfiguration(String host,int port) {
        super(host,port);
    }

    public long getSelectBlockTime() {
        return selectBlockTime;
    }

    public void setSelectBlockTime(long selectBlockTime) {
        this.selectBlockTime = selectBlockTime;
    }

    public boolean isNioBugChecker() {
        return nioBugChecker;
    }

    public void setNioBugChecker(boolean nioBugChecker) {
        this.nioBugChecker = nioBugChecker;
    }

    public long getNioBugIntervalThreshold() {
        return nioBugIntervalThreshold;
    }

    public void setNioBugIntervalThreshold(long nioBugIntervalThreshold) {
        this.nioBugIntervalThreshold = nioBugIntervalThreshold;
    }

    public int getNioBugPossibleCount() {
        return nioBugPossibleCount;
    }

    public void setNioBugPossibleCount(int nioBugPossibleCount) {
        this.nioBugPossibleCount = nioBugPossibleCount;
    }

    public long getIoReactorBlockTime() {
        return ioReactorBlockTime;
    }

    public void setIoReactorBlockTime(long ioReactorBlockTime) {
        this.ioReactorBlockTime = ioReactorBlockTime;
    }

    public Class<? extends Encoder<?>> getEncoderClass() {
        return encoderClass;
    }

    public void setEncoderClass(Class<? extends Encoder<?>> encoderClass) {
        this.encoderClass = encoderClass;
    }

    public Class<? extends Decoder<?>> getDecoderClass() {
        return decoderClass;
    }

    public void setDecoderClass(Class<? extends Decoder<?>> decoderClass) {
        this.decoderClass = decoderClass;
    }

    public int getBufferCapacity() {
        return bufferCapacity;
    }

    public void setBufferCapacity(int bufferCapacity) {
        this.bufferCapacity = bufferCapacity;
    }
}
